/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJDialog1.java
 *
 * Created on 2011-7-3, 0:43:16
 */
package seso;

import java.awt.Graphics;
import org.jdesktop.application.Action;

import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

/**
 *
 * @author Administrator
 */
public class MaintDialog extends javax.swing.JDialog {

    public String progID = "SES000";
    public String progDescription = "RHomeDialog Class";
    public javax.swing.JDialog prevDialog = null;
    // Program index to identity each dialog entered by user
    public int indexMiniProgID = -1;
    public boolean IncreaseIndexMiniProgID = true;
    public javax.swing.JFrame parent;
    public javax.swing.JPanel miniProgListJPanel = null;
    private Robot robot = null;
    // X, Y :
    private int defaultX = 9, defaultY = 9, defaultWidth = 1000, defaultHeight = 700;
    public int currentX = 9, currentY = 9, currentWidth = 1000, currentHeight = 700;
    public boolean isMaximized = false;
    private int titleBarMouseX = 0, titleBarMouseY = 0;
    public int dlgDataMode = AppSetting.DISPLAY_MODE;
    public boolean isBrowseDialog = true;
    public int defaultDataAeraPanelRigthMargin = 150;
    public int currentDataAeraPanelRigthMargin = defaultDataAeraPanelRigthMargin;


    public MaintDialog(javax.swing.JFrame parent, boolean modal) {
        super(parent, modal);
        
        /// Firstly setVisible(false), do not show the procedure before set visible
        setVisible(false);

        this.parent = parent;

        initComponents();
        refreshToolsBar();

        setControl();

        paintRootComponent();

        try {
            robot = new Robot();
        } catch (Exception irnore) {
        }
    }

    public void setProgTitle(String progID, String progDescription) {
        this.progID = progID;
        this.progDescription = progDescription;
        progTitleJLabel.setText("M3 " + progDescription + " - " + progID + "   " + "Vamsonite Company Limited Studio East Ltd");
    }

    public void setPrevDialog(javax.swing.JDialog prevDialog) {
        this.prevDialog = prevDialog;
    }

    private void setControl() {
        // Inital Location and Size
        if (!java.beans.Beans.isDesignTime()) {
            defaultWidth = parent.getWidth() - defaultX * 2;
            defaultHeight = parent.getHeight() - defaultY * 2 - 3; // Extra margin
        }

        currentWidth = defaultWidth * 5 / 6;
        currentX = (parent.getWidth() - currentWidth) / 2;
        currentY = defaultY + 30;
        currentHeight = defaultHeight - 30;

        setLocation(currentX, currentY);
        setSize(currentWidth, currentHeight);
        setPreferredSize(new java.awt.Dimension(currentWidth, currentHeight));
        // Inital Location and Size

        setProgTitle(progID, progDescription);
    }

    public void setMiniProgListJPanel(javax.swing.JPanel miniProgListJPanel, int indexMiniProgID) {
        this.miniProgListJPanel = miniProgListJPanel;
        this.indexMiniProgID = indexMiniProgID;
    }

    public void paintRootComponent() {
        int width = getWidth(), height = getHeight();

        rDialogTitleToolsBackground.setSize(width, rDialogTitleToolsBackground.getHeight());

        titleBarJPanel.setSize(width, titleBarJPanel.getHeight());
        progTitleJLabel.setSize(width - 100, progTitleJLabel.getHeight());

        cmdClose.setLocation(width - cmdClose.getWidth() - 10, cmdClose.getY());

        cmdMaximize.setLocation(cmdClose.getX() - cmdMaximize.getWidth() - 3, cmdMaximize.getY());
        cmdRestore.setLocation(cmdMaximize.getX(), cmdMaximize.getY());

        cmdMinimize.setLocation(cmdMaximize.getX() - cmdMinimize.getWidth() - 3, cmdMinimize.getY());

        cmdRestore.setVisible(isMaximized);
        cmdMaximize.setVisible(!isMaximized);

        rDialogStatusBarBackground.setSize(getWidth(), rDialogStatusBarBackground.getHeight());
        rDialogStatusBarBackground.setLocation(0, getHeight() - rDialogStatusBarBackground.getHeight());

        topBorderJPanel.setSize(width, topBorderJPanel.getHeight());

        bottomBorderJPanel.setLocation(0, height - bottomBorderJPanel.getHeight());
        bottomBorderJPanel.setSize(width, bottomBorderJPanel.getHeight());

        leftBorderJPanel.setSize(leftBorderJPanel.getWidth(), height);

        rightBorderJPanel.setLocation(width - rightBorderJPanel.getWidth(), 0);
        rightBorderJPanel.setSize(rightBorderJPanel.getWidth(), height);

        dlgMenuScaleHelpJLabel.setLocation(width - dlgMenuScaleHelpJLabel.getWidth() - 5, dlgMenuScaleHelpJLabel.getY());

    }

    public void paintDialogComponent() {
    }

    public void dialogShortcutSeparatorMouseDragged(java.awt.event.MouseEvent evt, RDialogShortcutExpandSwitch rDialogShortcutExpandSwitch) {
        if (rDialogShortcutExpandSwitch.isShowExpandImage()) {
            return;
        }

        int newMargin = defaultDataAeraPanelRigthMargin - evt.getX();

        if (newMargin < 18 || newMargin > getWidth() - 200) // set minimum and maximum right margin for DialogDataAeraPanel
        {
            return;
        }

        defaultDataAeraPanelRigthMargin = newMargin;
        paintTemplateComponent();
        paintDialogComponent();
    }

    public void dialogShortcutExpandSwitchMouseClicked(java.awt.event.MouseEvent evt, RDialogShortcutExpandSwitch rDialogShortcutExpandSwitch, RDialogShortcutSeparator rDialogShortcutSeparator) {
        int minMargin = 20;

        if (isMaximized) {

            if (rDialogShortcutExpandSwitch.isShowExpandImage()) {
                currentDataAeraPanelRigthMargin = defaultDataAeraPanelRigthMargin;
                defaultDataAeraPanelRigthMargin = minMargin;
            } else {
                defaultDataAeraPanelRigthMargin = currentDataAeraPanelRigthMargin;
            }
            paintTemplateComponent();
            paintDialogComponent();

        } else {
            if (rDialogShortcutExpandSwitch.isShowExpandImage()) {
                setSize(getWidth() - defaultDataAeraPanelRigthMargin + minMargin, getHeight());
                currentDataAeraPanelRigthMargin = defaultDataAeraPanelRigthMargin;
                defaultDataAeraPanelRigthMargin = minMargin;
            } else {
                defaultDataAeraPanelRigthMargin = currentDataAeraPanelRigthMargin;
                setSize(getWidth() + defaultDataAeraPanelRigthMargin - minMargin, getHeight());
            }

            paintTemplateComponent();
            paintDialogComponent();
            currentX = (parent.getWidth() - getWidth()) / 2;
            setLocation(currentX, currentY);
        }

        if (rDialogShortcutExpandSwitch.isShowExpandImage()) {
            rDialogShortcutSeparator.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        } else {
            rDialogShortcutSeparator.setCursor(new java.awt.Cursor(java.awt.Cursor.E_RESIZE_CURSOR));
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        topBorderJPanel = new javax.swing.JPanel();
        leftBorderJPanel = new javax.swing.JPanel();
        rightBorderJPanel = new javax.swing.JPanel();
        bottomBorderJPanel = new javax.swing.JPanel();
        titleBarJPanel = new javax.swing.JPanel();
        cmdMinimize = new javax.swing.JButton();
        cmdMaximize = new javax.swing.JButton();
        cmdRestore = new javax.swing.JButton();
        cmdClose = new javax.swing.JButton();
        progTitleJLabel = new javax.swing.JLabel();
        ToolsBarJPanel = new javax.swing.JPanel();
        cmdCreate = new javax.swing.JButton();
        cmdSelect = new javax.swing.JButton();
        cmdChange = new javax.swing.JButton();
        cmdCopy = new javax.swing.JButton();
        cmdDisplay = new javax.swing.JButton();
        cmdDelete = new javax.swing.JButton();
        cmdRefresh = new javax.swing.JButton();
        cmdDoc = new javax.swing.JButton();
        dlgMenuScaleHelpJLabel = new javax.swing.JLabel();
        dlgMenuBarJLabel = new javax.swing.JLabel();
        rDialogTitleToolsBackground = new seso.RDialogTitleToolsBackground();
        rDialogStatusBarBackground = new seso.RDialogStatusBarBackground();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(320, 240));
        setName("RHomeDialog"); // NOI18N
        setResizable(false);
        setUndecorated(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(null);

        topBorderJPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
        topBorderJPanel.setName("topBorderJPanel"); // NOI18N
        topBorderJPanel.setOpaque(false);
        topBorderJPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                topBorderJPanelMouseDragged(evt);
            }
        });

        javax.swing.GroupLayout topBorderJPanelLayout = new javax.swing.GroupLayout(topBorderJPanel);
        topBorderJPanel.setLayout(topBorderJPanelLayout);
        topBorderJPanelLayout.setHorizontalGroup(
            topBorderJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1000, Short.MAX_VALUE)
        );
        topBorderJPanelLayout.setVerticalGroup(
            topBorderJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 4, Short.MAX_VALUE)
        );

        getContentPane().add(topBorderJPanel);
        topBorderJPanel.setBounds(0, 0, 1000, 4);

        leftBorderJPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.W_RESIZE_CURSOR));
        leftBorderJPanel.setName("leftBorderJPanel"); // NOI18N
        leftBorderJPanel.setOpaque(false);
        leftBorderJPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                leftBorderJPanelMouseDragged(evt);
            }
        });

        javax.swing.GroupLayout leftBorderJPanelLayout = new javax.swing.GroupLayout(leftBorderJPanel);
        leftBorderJPanel.setLayout(leftBorderJPanelLayout);
        leftBorderJPanelLayout.setHorizontalGroup(
            leftBorderJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 4, Short.MAX_VALUE)
        );
        leftBorderJPanelLayout.setVerticalGroup(
            leftBorderJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );

        getContentPane().add(leftBorderJPanel);
        leftBorderJPanel.setBounds(0, 0, 4, 600);

        rightBorderJPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.E_RESIZE_CURSOR));
        rightBorderJPanel.setName("rightBorderJPanel"); // NOI18N
        rightBorderJPanel.setOpaque(false);
        rightBorderJPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                rightBorderJPanelMouseDragged(evt);
            }
        });

        javax.swing.GroupLayout rightBorderJPanelLayout = new javax.swing.GroupLayout(rightBorderJPanel);
        rightBorderJPanel.setLayout(rightBorderJPanelLayout);
        rightBorderJPanelLayout.setHorizontalGroup(
            rightBorderJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 4, Short.MAX_VALUE)
        );
        rightBorderJPanelLayout.setVerticalGroup(
            rightBorderJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );

        getContentPane().add(rightBorderJPanel);
        rightBorderJPanel.setBounds(930, -40, 4, 600);

        bottomBorderJPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.S_RESIZE_CURSOR));
        bottomBorderJPanel.setName("bottomBorderJPanel"); // NOI18N
        bottomBorderJPanel.setOpaque(false);
        bottomBorderJPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                bottomBorderJPanelMouseDragged(evt);
            }
        });

        javax.swing.GroupLayout bottomBorderJPanelLayout = new javax.swing.GroupLayout(bottomBorderJPanel);
        bottomBorderJPanel.setLayout(bottomBorderJPanelLayout);
        bottomBorderJPanelLayout.setHorizontalGroup(
            bottomBorderJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1000, Short.MAX_VALUE)
        );
        bottomBorderJPanelLayout.setVerticalGroup(
            bottomBorderJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 4, Short.MAX_VALUE)
        );

        getContentPane().add(bottomBorderJPanel);
        bottomBorderJPanel.setBounds(0, 660, 1000, 4);

        titleBarJPanel.setName("titleBarJPanel"); // NOI18N
        titleBarJPanel.setOpaque(false);
        titleBarJPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                titleBarJPanelMousePressed(evt);
            }
        });
        titleBarJPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                titleBarJPanelMouseDragged(evt);
            }
        });
        titleBarJPanel.setLayout(null);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(seso.SesoApp.class).getContext().getActionMap(MaintDialog.class, this);
        cmdMinimize.setAction(actionMap.get("cmdMinimizeAction")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(seso.SesoApp.class).getContext().getResourceMap(MaintDialog.class);
        cmdMinimize.setIcon(resourceMap.getIcon("cmdMinimize.icon")); // NOI18N
        cmdMinimize.setText(resourceMap.getString("cmdMinimize.text")); // NOI18N
        cmdMinimize.setBorder(null);
        cmdMinimize.setBorderPainted(false);
        cmdMinimize.setContentAreaFilled(false);
        cmdMinimize.setFocusPainted(false);
        cmdMinimize.setFocusable(false);
        cmdMinimize.setName("cmdMinimize"); // NOI18N
        cmdMinimize.setPressedIcon(resourceMap.getIcon("cmdMinimize.pressedIcon")); // NOI18N
        cmdMinimize.setRolloverIcon(resourceMap.getIcon("cmdMinimize.rolloverIcon")); // NOI18N
        titleBarJPanel.add(cmdMinimize);
        cmdMinimize.setBounds(640, 3, 19, 19);

        cmdMaximize.setAction(actionMap.get("cmdMaximizeAction")); // NOI18N
        cmdMaximize.setIcon(resourceMap.getIcon("cmdMaximize.icon")); // NOI18N
        cmdMaximize.setText(resourceMap.getString("cmdMaximize.text")); // NOI18N
        cmdMaximize.setBorder(null);
        cmdMaximize.setBorderPainted(false);
        cmdMaximize.setContentAreaFilled(false);
        cmdMaximize.setFocusPainted(false);
        cmdMaximize.setFocusable(false);
        cmdMaximize.setName("cmdMaximize"); // NOI18N
        cmdMaximize.setPressedIcon(resourceMap.getIcon("cmdMaximize.pressedIcon")); // NOI18N
        cmdMaximize.setRolloverIcon(resourceMap.getIcon("cmdMaximize.rolloverIcon")); // NOI18N
        titleBarJPanel.add(cmdMaximize);
        cmdMaximize.setBounds(670, 3, 19, 19);

        cmdRestore.setAction(actionMap.get("cmdRestoreAction")); // NOI18N
        cmdRestore.setIcon(resourceMap.getIcon("cmdRestore.icon")); // NOI18N
        cmdRestore.setText(resourceMap.getString("cmdRestore.text")); // NOI18N
        cmdRestore.setBorder(null);
        cmdRestore.setBorderPainted(false);
        cmdRestore.setContentAreaFilled(false);
        cmdRestore.setFocusable(false);
        cmdRestore.setMaximumSize(new java.awt.Dimension(20, 19));
        cmdRestore.setMinimumSize(new java.awt.Dimension(20, 19));
        cmdRestore.setName("cmdRestore"); // NOI18N
        cmdRestore.setPreferredSize(new java.awt.Dimension(20, 19));
        cmdRestore.setPressedIcon(resourceMap.getIcon("cmdRestore.pressedIcon")); // NOI18N
        cmdRestore.setRolloverIcon(resourceMap.getIcon("cmdRestore.rolloverIcon")); // NOI18N
        titleBarJPanel.add(cmdRestore);
        cmdRestore.setBounds(700, 3, 20, 19);

        cmdClose.setAction(actionMap.get("cmdCloseAction")); // NOI18N
        cmdClose.setIcon(resourceMap.getIcon("cmdClose.icon")); // NOI18N
        cmdClose.setText(resourceMap.getString("cmdClose.text")); // NOI18N
        cmdClose.setBorder(null);
        cmdClose.setBorderPainted(false);
        cmdClose.setContentAreaFilled(false);
        cmdClose.setFocusPainted(false);
        cmdClose.setFocusable(false);
        cmdClose.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdClose.setName("cmdClose"); // NOI18N
        cmdClose.setPressedIcon(resourceMap.getIcon("cmdClose.pressedIcon")); // NOI18N
        cmdClose.setRolloverIcon(resourceMap.getIcon("cmdClose.rolloverIcon")); // NOI18N
        titleBarJPanel.add(cmdClose);
        cmdClose.setBounds(730, 3, 19, 19);

        progTitleJLabel.setFont(resourceMap.getFont("progTitleJLabel.font")); // NOI18N
        progTitleJLabel.setForeground(resourceMap.getColor("progTitleJLabel.foreground")); // NOI18N
        progTitleJLabel.setText(resourceMap.getString("progTitleJLabel.text")); // NOI18N
        progTitleJLabel.setName("progTitleJLabel"); // NOI18N
        titleBarJPanel.add(progTitleJLabel);
        progTitleJLabel.setBounds(10, 3, 890, 20);

        getContentPane().add(titleBarJPanel);
        titleBarJPanel.setBounds(0, 0, 790, 28);

        ToolsBarJPanel.setName("ToolsBarJPanel"); // NOI18N
        ToolsBarJPanel.setOpaque(false);
        ToolsBarJPanel.setLayout(null);

        cmdCreate.setAction(actionMap.get("cmdCreateAction")); // NOI18N
        cmdCreate.setIcon(resourceMap.getIcon("cmdCreate.icon")); // NOI18N
        cmdCreate.setText(resourceMap.getString("cmdCreate.text")); // NOI18N
        cmdCreate.setBorder(null);
        cmdCreate.setBorderPainted(false);
        cmdCreate.setContentAreaFilled(false);
        cmdCreate.setDisabledIcon(resourceMap.getIcon("cmdCreate.disabledIcon")); // NOI18N
        cmdCreate.setFocusPainted(false);
        cmdCreate.setFocusable(false);
        cmdCreate.setName("cmdCreate"); // NOI18N
        cmdCreate.setPressedIcon(resourceMap.getIcon("cmdCreate.pressedIcon")); // NOI18N
        cmdCreate.setRolloverIcon(resourceMap.getIcon("cmdCreate.rolloverIcon")); // NOI18N
        ToolsBarJPanel.add(cmdCreate);
        cmdCreate.setBounds(1, 1, 37, 37);

        cmdSelect.setIcon(resourceMap.getIcon("cmdSelect.icon")); // NOI18N
        cmdSelect.setText(resourceMap.getString("cmdSelect.text")); // NOI18N
        cmdSelect.setBorder(null);
        cmdSelect.setBorderPainted(false);
        cmdSelect.setContentAreaFilled(false);
        cmdSelect.setDisabledIcon(resourceMap.getIcon("cmdSelect.disabledIcon")); // NOI18N
        cmdSelect.setFocusPainted(false);
        cmdSelect.setFocusable(false);
        cmdSelect.setName("cmdSelect"); // NOI18N
        cmdSelect.setPressedIcon(resourceMap.getIcon("cmdSelect.pressedIcon")); // NOI18N
        cmdSelect.setRolloverIcon(resourceMap.getIcon("cmdSelect.rolloverIcon")); // NOI18N
        ToolsBarJPanel.add(cmdSelect);
        cmdSelect.setBounds(38, 1, 37, 37);

        cmdChange.setAction(actionMap.get("cmdChangeAction")); // NOI18N
        cmdChange.setIcon(resourceMap.getIcon("cmdChange.icon")); // NOI18N
        cmdChange.setText(resourceMap.getString("cmdChange.text")); // NOI18N
        cmdChange.setBorder(null);
        cmdChange.setBorderPainted(false);
        cmdChange.setContentAreaFilled(false);
        cmdChange.setDisabledIcon(resourceMap.getIcon("cmdChange.disabledIcon")); // NOI18N
        cmdChange.setFocusPainted(false);
        cmdChange.setFocusable(false);
        cmdChange.setName("cmdChange"); // NOI18N
        cmdChange.setPressedIcon(resourceMap.getIcon("cmdChange.pressedIcon")); // NOI18N
        cmdChange.setRolloverIcon(resourceMap.getIcon("cmdChange.rolloverIcon")); // NOI18N
        ToolsBarJPanel.add(cmdChange);
        cmdChange.setBounds(75, 1, 37, 37);

        cmdCopy.setIcon(resourceMap.getIcon("cmdCopy.icon")); // NOI18N
        cmdCopy.setText(resourceMap.getString("cmdCopy.text")); // NOI18N
        cmdCopy.setBorder(null);
        cmdCopy.setBorderPainted(false);
        cmdCopy.setContentAreaFilled(false);
        cmdCopy.setDisabledIcon(resourceMap.getIcon("cmdCopy.disabledIcon")); // NOI18N
        cmdCopy.setFocusPainted(false);
        cmdCopy.setFocusable(false);
        cmdCopy.setName("cmdCopy"); // NOI18N
        cmdCopy.setPressedIcon(resourceMap.getIcon("cmdCopy.pressedIcon")); // NOI18N
        cmdCopy.setRolloverIcon(resourceMap.getIcon("cmdCopy.rolloverIcon")); // NOI18N
        ToolsBarJPanel.add(cmdCopy);
        cmdCopy.setBounds(112, 1, 37, 37);

        cmdDisplay.setAction(actionMap.get("cmdDisplayAction")); // NOI18N
        cmdDisplay.setIcon(resourceMap.getIcon("cmdDisplay.icon")); // NOI18N
        cmdDisplay.setText(resourceMap.getString("cmdDisplay.text")); // NOI18N
        cmdDisplay.setBorder(null);
        cmdDisplay.setBorderPainted(false);
        cmdDisplay.setContentAreaFilled(false);
        cmdDisplay.setDisabledIcon(resourceMap.getIcon("cmdDisplay.disabledIcon")); // NOI18N
        cmdDisplay.setFocusPainted(false);
        cmdDisplay.setFocusable(false);
        cmdDisplay.setName("cmdDisplay"); // NOI18N
        cmdDisplay.setPressedIcon(resourceMap.getIcon("cmdDisplay.pressedIcon")); // NOI18N
        cmdDisplay.setRolloverIcon(resourceMap.getIcon("cmdDisplay.rolloverIcon")); // NOI18N
        ToolsBarJPanel.add(cmdDisplay);
        cmdDisplay.setBounds(149, 1, 37, 37);

        cmdDelete.setIcon(resourceMap.getIcon("cmdDelete.icon")); // NOI18N
        cmdDelete.setText(resourceMap.getString("cmdDelete.text")); // NOI18N
        cmdDelete.setBorder(null);
        cmdDelete.setBorderPainted(false);
        cmdDelete.setContentAreaFilled(false);
        cmdDelete.setDisabledIcon(resourceMap.getIcon("cmdDelete.disabledIcon")); // NOI18N
        cmdDelete.setFocusPainted(false);
        cmdDelete.setFocusable(false);
        cmdDelete.setName("cmdDelete"); // NOI18N
        cmdDelete.setPressedIcon(resourceMap.getIcon("cmdDelete.pressedIcon")); // NOI18N
        cmdDelete.setRolloverIcon(resourceMap.getIcon("cmdDelete.rolloverIcon")); // NOI18N
        ToolsBarJPanel.add(cmdDelete);
        cmdDelete.setBounds(186, 1, 37, 37);

        cmdRefresh.setAction(actionMap.get("cmdRefreshAction")); // NOI18N
        cmdRefresh.setIcon(resourceMap.getIcon("cmdRefresh.icon")); // NOI18N
        cmdRefresh.setText(resourceMap.getString("cmdRefresh.text")); // NOI18N
        cmdRefresh.setBorder(null);
        cmdRefresh.setBorderPainted(false);
        cmdRefresh.setContentAreaFilled(false);
        cmdRefresh.setFocusPainted(false);
        cmdRefresh.setFocusable(false);
        cmdRefresh.setName("cmdRefresh"); // NOI18N
        cmdRefresh.setPressedIcon(resourceMap.getIcon("cmdRefresh.pressedIcon")); // NOI18N
        cmdRefresh.setRolloverIcon(resourceMap.getIcon("cmdRefresh.rolloverIcon")); // NOI18N
        ToolsBarJPanel.add(cmdRefresh);
        cmdRefresh.setBounds(223, 1, 37, 37);

        cmdDoc.setIcon(resourceMap.getIcon("cmdDoc.icon")); // NOI18N
        cmdDoc.setText(resourceMap.getString("cmdDoc.text")); // NOI18N
        cmdDoc.setBorder(null);
        cmdDoc.setBorderPainted(false);
        cmdDoc.setContentAreaFilled(false);
        cmdDoc.setDisabledIcon(resourceMap.getIcon("cmdDoc.disabledIcon")); // NOI18N
        cmdDoc.setEnabled(false);
        cmdDoc.setFocusPainted(false);
        cmdDoc.setFocusable(false);
        cmdDoc.setName("cmdDoc"); // NOI18N
        ToolsBarJPanel.add(cmdDoc);
        cmdDoc.setBounds(260, 1, 37, 37);

        getContentPane().add(ToolsBarJPanel);
        ToolsBarJPanel.setBounds(285, 31, 310, 39);

        dlgMenuScaleHelpJLabel.setIcon(resourceMap.getIcon("dlgMenuScaleHelpJLabel.icon")); // NOI18N
        dlgMenuScaleHelpJLabel.setText(resourceMap.getString("dlgMenuScaleHelpJLabel.text")); // NOI18N
        dlgMenuScaleHelpJLabel.setName("dlgMenuScaleHelpJLabel"); // NOI18N
        getContentPane().add(dlgMenuScaleHelpJLabel);
        dlgMenuScaleHelpJLabel.setBounds(900, 31, 76, 39);

        dlgMenuBarJLabel.setIcon(resourceMap.getIcon("dlgMenuBarJLabel.icon")); // NOI18N
        dlgMenuBarJLabel.setText(resourceMap.getString("dlgMenuBarJLabel.text")); // NOI18N
        dlgMenuBarJLabel.setName("dlgMenuBarJLabel"); // NOI18N
        getContentPane().add(dlgMenuBarJLabel);
        dlgMenuBarJLabel.setBounds(0, 31, 286, 39);

        rDialogTitleToolsBackground.setText(resourceMap.getString("rDialogTitleToolsBackground.text")); // NOI18N
        rDialogTitleToolsBackground.setName("rDialogTitleToolsBackground"); // NOI18N
        getContentPane().add(rDialogTitleToolsBackground);
        rDialogTitleToolsBackground.setBounds(0, 0, 1000, 70);

        rDialogStatusBarBackground.setText(resourceMap.getString("rDialogStatusBarBackground.text")); // NOI18N
        rDialogStatusBarBackground.setName("rDialogStatusBarBackground"); // NOI18N
        getContentPane().add(rDialogStatusBarBackground);
        rDialogStatusBarBackground.setBounds(0, 650, 1000, 20);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

        int originalX = getX(), originalY = getY(), originalWidth = getWidth(), originalHeight = getHeight();

        // Screen snapshot
        BufferedImage dialogImage = robot.createScreenCapture(new Rectangle(originalX, originalY, originalWidth, originalHeight));

        if (IncreaseIndexMiniProgID) {
            ((HomePage) parent).addMiniProg((javax.swing.JDialog) this, originalX, originalY, progID, progDescription, dialogImage);
        } else {
            ((HomePage) parent).replaceMiniProg(indexMiniProgID, (javax.swing.JDialog) this, originalX, originalY, progID, progDescription, dialogImage);
        }

        setResizable(true);
    }//GEN-LAST:event_formWindowOpened

    public void replaceMiniProg() {

        int originalX = getX(), originalY = getY(), originalWidth = getWidth(), originalHeight = getHeight();

        // Screen snapshot
        BufferedImage dialogImage = robot.createScreenCapture(new Rectangle(originalX, originalY, originalWidth, originalHeight));

        ((HomePage) parent).replaceMiniProg(indexMiniProgID, (javax.swing.JDialog) this, originalX, originalY, progID, progDescription, dialogImage);
    }

    private void titleBarJPanelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_titleBarJPanelMouseDragged
        setLocation(getX() + evt.getX() - titleBarMouseX, getY() + evt.getY() - titleBarMouseY);
    }//GEN-LAST:event_titleBarJPanelMouseDragged

    private void titleBarJPanelMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_titleBarJPanelMousePressed
        titleBarMouseX = evt.getX();
        titleBarMouseY = evt.getY();
    }//GEN-LAST:event_titleBarJPanelMousePressed

    private void topBorderJPanelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_topBorderJPanelMouseDragged
        setLocation(getX(), getY() + evt.getY());
        setSize(getWidth(), getHeight() - (evt.getY()));
        isMaximized = false;
        paintRootComponent();
    }//GEN-LAST:event_topBorderJPanelMouseDragged

    private void bottomBorderJPanelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bottomBorderJPanelMouseDragged
        setSize(getWidth(), getHeight() + (evt.getY()));
        isMaximized = false;
        paintRootComponent();
    }//GEN-LAST:event_bottomBorderJPanelMouseDragged

    private void leftBorderJPanelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_leftBorderJPanelMouseDragged
        setLocation(getX() + evt.getX(), getY());
        setSize(getWidth() - evt.getX(), getHeight());
        isMaximized = false;
        paintRootComponent();
    }//GEN-LAST:event_leftBorderJPanelMouseDragged

    private void rightBorderJPanelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rightBorderJPanelMouseDragged
        setSize(getWidth() + evt.getX(), getHeight());
        isMaximized = false;
        paintRootComponent();
    }//GEN-LAST:event_rightBorderJPanelMouseDragged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                MaintDialog dialog = new MaintDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    @Action
    public void cmdMinimizeAction() {
        repaint();
        int originalX = getX(), originalY = getY(), originalWidth = getWidth(), originalHeight = getHeight();


        // Adjust location if off-screen
        boolean needWait = false;
        if ((originalX < 0)
                || (originalY < 0)
                || (parent != null && (originalX + originalWidth > parent.getWidth() || originalY + originalHeight > parent.getHeight()))) {
            setLocation(0, 0);
            needWait = true;
        }

        // 对示屏幕外的，稍等一下以便等待截屏完成
        if (needWait) {
            try {
                Thread.sleep(10);
            } catch (Exception ignore) {
            }
        }

        // Screen snapshot
        BufferedImage dialogImage = robot.createScreenCapture(new Rectangle(getX(), getY(), originalWidth, originalHeight));


        setVisible(false);

        // Added when windows opened, NO need to add again
        //((HomePage) parent).addMiniProg((javax.swing.JDialog) this, originalX, originalY, progID, progDescription, dialogImage);

        int goalX = 0;
        int goalY = 50; // 50 : the getY() of each mini bitmap
        for (int i = 0; i < miniProgListJPanel.getComponentCount(); i++) {
            if (miniProgListJPanel.getComponent(i).getName().equals("rMX" + this.indexMiniProgID)) {
                goalX = 114 * i + 11;   // 114 : (getWidth + interval)
                ((RMiniProgJPanel) (miniProgListJPanel.getComponent(i))).updateLocationAndImage(originalX, originalY, dialogImage);
                break;
            }
        }

        //JOptionPane.showMessageDialog(null, "x : " + goalX + ", y: " + goalY);

        // 显示最小化图标的变化过程
        RMiniImageJDialog dlg = new RMiniImageJDialog(null, true);
        dlg.setImage((java.awt.Image) dialogImage, originalX, originalY, originalWidth, originalHeight, goalX, goalY, true);
        SesoApp.getApplication().show(dlg);
        // 显示最小化图标的变化过程
    }

    public void paintTemplateComponent() {
    }

    public void paintTemplateComponent(
            RDialogDataAeraPanel rDialogDataAeraPanel,
            RDialogShortcutSeparator rDialogShortcutSeparator, RDialogShortcutExpandSwitch rDialogShortcutExpandSwitch,
            RDialogShortcutPanel rDialogShortcutPanel, RDiglogShortcutSettingButton rDiglogShortcutSettingButton,
            RPanel bottomNavigatorPanel, RNavigatorCloseButton rNavigatorCloseButton, RNavigatorPrevButton rNavigatorPrevButton, RNavigatorNextButton rNavigatorNextButton,
            RPanel dialogTabbedPanel) {

        int width = getWidth(), height = getHeight();

        rDialogDataAeraPanel.setSize(width - defaultDataAeraPanelRigthMargin, height - 90); // 150 : default right margin,  90: ToolsBar and StatusBar total margin

        rDialogShortcutSeparator.setLocation(rDialogDataAeraPanel.getX() + rDialogDataAeraPanel.getWidth(), rDialogDataAeraPanel.getY());
        rDialogShortcutSeparator.setSize(rDialogShortcutSeparator.getWidth(), rDialogDataAeraPanel.getHeight());

        rDialogShortcutPanel.setLocation(rDialogShortcutSeparator.getX() + rDialogShortcutSeparator.getWidth(), rDialogShortcutSeparator.getY());
        rDialogShortcutPanel.setSize(width - rDialogDataAeraPanel.getWidth() - rDialogShortcutSeparator.getWidth(), rDialogDataAeraPanel.getHeight());

        bottomNavigatorPanel.setLocation(10, rDialogDataAeraPanel.getHeight() - 15 - bottomNavigatorPanel.getHeight());
        bottomNavigatorPanel.setSize(rDialogDataAeraPanel.getWidth() - bottomNavigatorPanel.getX(), bottomNavigatorPanel.getHeight());

        rNavigatorCloseButton.setLocation(0, 0);
        rNavigatorNextButton.setLocation(bottomNavigatorPanel.getWidth() - rNavigatorNextButton.getWidth(), 0);
        rNavigatorPrevButton.setLocation(rNavigatorNextButton.getX() - rNavigatorPrevButton.getWidth(), 0);

        dialogTabbedPanel.setLocation(bottomNavigatorPanel.getX() + 100, bottomNavigatorPanel.getY() + 3);
        dialogTabbedPanel.setSize(bottomNavigatorPanel.getWidth() - 270, dialogTabbedPanel.getHeight());

        int startX = dialogTabbedPanel.getWidth();
        for (int i = dialogTabbedPanel.getComponentCount() - 1; i >= 0; i--) {
            dialogTabbedPanel.getComponent(i).setLocation(startX - dialogTabbedPanel.getComponent(i).getWidth(), 0);
            startX = dialogTabbedPanel.getComponent(i).getX();
        }

        int widthDialogShortcutPanel = rDialogShortcutPanel.getWidth();
        rDiglogShortcutSettingButton.setLocation(widthDialogShortcutPanel - rDiglogShortcutSettingButton.getWidth() - 12, 5);
        rDialogShortcutExpandSwitch.setLocation(widthDialogShortcutPanel - rDialogShortcutExpandSwitch.getWidth() - 3, (rDialogShortcutPanel.getHeight() - rDialogShortcutExpandSwitch.getHeight()) / 2);
        for (int i = 0; i < rDialogShortcutPanel.getComponentCount(); i++) {
            if (!rDialogShortcutPanel.getComponent(i).getName().equals("rDiglogShortcutSettingButton")
                    && !rDialogShortcutPanel.getComponent(i).getName().equals("rDialogShortcutExpandSwitch")) {
                rDialogShortcutPanel.getComponent(i).setSize(widthDialogShortcutPanel - rDialogShortcutPanel.getComponent(i).getX() - 8, rDialogShortcutPanel.getComponent(i).getHeight());
            }
        }
    }

    public void refreshTableHeaderField() {
    }

    public void refreshTableHeaderField(JScrollPane masterScrollPane, JTable masterTable, String headerText, JPanel fldJPanel, JComponent fldJComponent) {
        int fldX = 5;
        int fldY = masterScrollPane.getY() + 15;

        int indexFound = -1;

        int locationX = masterTable.getX();
        for (int i = 0; i < masterTable.getColumnCount(); i++) {
            if (masterTable.getColumnModel().getColumn(i).getHeaderValue().toString().equals(headerText)) {
                indexFound = i;
                break;
            } else {
                locationX = locationX + masterTable.getColumnModel().getColumn(i).getWidth();
            }
        }

        if (indexFound >= 0) {
            fldJPanel.setSize(masterTable.getColumnModel().getColumn(indexFound).getWidth() - fldX * 2, fldJComponent.getHeight());
            fldJComponent.setSize(fldJPanel.getWidth(), fldJComponent.getHeight());

            if (locationX >= fldX && locationX + fldJComponent.getWidth() <= masterScrollPane.getWidth()) {
                fldJComponent.setLocation(0, 0);
                fldJPanel.setLocation(masterScrollPane.getX() + locationX + fldX, fldY);
                fldJPanel.setVisible(true);
            } else if (locationX < fldX && locationX + fldJComponent.getWidth() > 0) {
                fldJComponent.setLocation(locationX, 0);
                fldJPanel.setLocation(masterScrollPane.getX() + fldX, fldY);
                fldJPanel.setSize(fldJPanel.getWidth() + locationX, fldJPanel.getHeight());
                fldJPanel.setVisible(true);
            } else if (locationX > 0 && locationX < masterScrollPane.getWidth() && locationX + fldX + fldJComponent.getWidth() > masterScrollPane.getWidth()) {
                fldJComponent.setLocation(0, 0);
                fldJPanel.setLocation(masterScrollPane.getX() + locationX + fldX, fldY);
                fldJPanel.setSize(masterScrollPane.getWidth() - locationX - fldX * 2, fldJPanel.getHeight());
                fldJComponent.setSize(fldJPanel.getWidth(), fldJComponent.getHeight());
                fldJPanel.setVisible(true);
            } else {
                fldJPanel.setVisible(false);
            }
        }
    }

    @Action
    public void cmdCloseAction() {
        if (this.indexMiniProgID < 0) {
            dispose();
            return;
        }

        dispose();

        for (int i = 0; i < miniProgListJPanel.getComponentCount(); i++) {
            if ((miniProgListJPanel.getComponent(i).getName()).equals("rMX" + indexMiniProgID)) {
                miniProgListJPanel.remove(i);
                break;
            }
        }

        int counterMiniProg = miniProgListJPanel.getComponentCount();

        //miniProgListJPanel.setSize(counterMiniProg * (getPreferredSize().width + 5), miniProgListJPanel.getHeight());
        miniProgListJPanel.setSize(counterMiniProg * 114, miniProgListJPanel.getHeight());

    }

    @Action
    public void cmdMaximizeAction() {
        currentX = getX();
        currentY = getY();
        currentWidth = getWidth();
        currentHeight = getHeight();
        setLocation(defaultX, defaultY);
        setSize(defaultWidth, defaultHeight);
        isMaximized = true;
        paintRootComponent();
    }

    @Action
    public void cmdRestoreAction() {
        setLocation(currentX, currentY);
        setSize(currentWidth, currentHeight);
        isMaximized = false;
        paintRootComponent();
    }

    public void refreshToolsBar() {
        cmdCreate.setEnabled(isBrowseDialog);
        cmdSelect.setEnabled(isBrowseDialog);
        cmdChange.setEnabled(isBrowseDialog);
        cmdCopy.setEnabled(isBrowseDialog);
        cmdDisplay.setEnabled(isBrowseDialog);
        cmdDelete.setEnabled(isBrowseDialog);
        //cmdRefresh.setEnabled(isBrowseDialog);
        cmdDoc.setEnabled(isBrowseDialog);
    }

    @Action
    public void cmdChangeAction() {
        dlgDataMode = AppSetting.CHANGE_MODE;
    }

    @Action
    public void cmdDisplayAction() {
        dlgDataMode = AppSetting.DISPLAY_MODE;
    }

    @Action
    public void cmdRefreshAction() {
    }

    @Action
    public void cmdCreateAction() {
        dlgDataMode = AppSetting.CREATE_MODE;
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        paintRootComponent();
        paintTemplateComponent();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ToolsBarJPanel;
    private javax.swing.JPanel bottomBorderJPanel;
    public javax.swing.JButton cmdChange;
    private javax.swing.JButton cmdClose;
    public javax.swing.JButton cmdCopy;
    public javax.swing.JButton cmdCreate;
    public javax.swing.JButton cmdDelete;
    public javax.swing.JButton cmdDisplay;
    public javax.swing.JButton cmdDoc;
    private javax.swing.JButton cmdMaximize;
    private javax.swing.JButton cmdMinimize;
    public javax.swing.JButton cmdRefresh;
    private javax.swing.JButton cmdRestore;
    public javax.swing.JButton cmdSelect;
    private javax.swing.JLabel dlgMenuBarJLabel;
    private javax.swing.JLabel dlgMenuScaleHelpJLabel;
    private javax.swing.JPanel leftBorderJPanel;
    private javax.swing.JLabel progTitleJLabel;
    protected seso.RDialogStatusBarBackground rDialogStatusBarBackground;
    protected seso.RDialogTitleToolsBackground rDialogTitleToolsBackground;
    private javax.swing.JPanel rightBorderJPanel;
    private javax.swing.JPanel titleBarJPanel;
    private javax.swing.JPanel topBorderJPanel;
    // End of variables declaration//GEN-END:variables
}
